﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.ObjectModel;
using 起点番茄小说助手.ExtUrls;
using 起点番茄小说助手.Models;

namespace 起点番茄小说助手.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private string _title = "起点番茄小说助手";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        public ObservableCollection<TreeViewItemModel> RootItems { get; set; }
        public DelegateCommand<TreeViewItemModel> SelectionCommand { get; set; }
        public MainWindowViewModel(IRegionManager region)
        {

            RootItems = new ObservableCollection<TreeViewItemModel>()
            {
                new TreeViewItemModel()
                {
                    Name="小说网站",
                     Icon= MaterialDesignThemes.Wpf.PackIconKind.Web,
                     Children=new ObservableCollection<TreeViewItemModel>
                     {
                         new TreeViewItemModel()
                         {
                             Id=1,
                             Name="起点中文网",
                             Url=ExtUrl.起点中文小说网URL,
                             Icon= MaterialDesignThemes.Wpf.PackIconKind.Star,
                         },
                         new TreeViewItemModel()
                         {
                             Id=1,
                              Name="番茄小说网",
                              Url=ExtUrl.番茄小说网URL,
                             Icon= MaterialDesignThemes.Wpf.PackIconKind.Star,
                         }
                     }
                }

            };

            SelectionCommand = new DelegateCommand<TreeViewItemModel>(x =>
            {
                if (x.Children != null)
                {
                    return;
                }

                bool res = x.Id switch
                {
                    1 => new Func<bool>(() =>
                    {
                        region.Regions["ContentRegion"].RequestNavigate(ExtUrl.WebsiteViewRegion, new NavigationParameters()
                        {
                            {"url",x.Url }
                        });
                        return true;
                    }).Invoke(),
                    2 => new Func<bool>(() =>
                    {
                        region.Regions["ContentRegion"].RequestNavigate(ExtUrl.NocelViewRegion, new NavigationParameters()
                        {
                            {"novel",x.Name }
                        });
                        return true;
                    }).Invoke()
                };
            });
        }
    }
}
